using System.Collections.Generic;
using System.Linq;
using Synapse.Framework.IoC.Bind;

namespace Synapse.Framework.IoC.Option
{
    internal class Options : IOptions
    {
        private readonly IList<Implemetation> implementations;
        private readonly Implemetation currentImplemetation;

        public Options(IList<Implemetation> implementations, Implemetation currentImplemetation)
        {
            this.implementations = implementations;
            this.currentImplemetation = currentImplemetation;
        }

        public IOptions Default()
        {
            currentImplemetation.Default = true;
            foreach (var item in implementations.Where(i => i != currentImplemetation))
                item.Default = false;
            return this;
        }

        public IOptions NewInstance()
        {
            currentImplemetation.IsNewInstance = true;
            return this;
        }

        public IOptions Singelton()
        {
            currentImplemetation.IsNewInstance = false;
            return this;
        }

        public IOptions ByKey(string key)
        {
            currentImplemetation.Key = key;
            return this;
        }
    }
}